const Mock = require('mockjs')
const count=100;
const SaleSlipList=[];
for(let i=0;i<count;i++){
    SaleSlipList.push(Mock.mock({
      id: '@increment',
      contractnumber:'@integer(209011234,579011234)',
      salesnumber:'@integer(409011234,879011234)',
      salesdate:'@datetime',
      customername:'@first',
      customerphone:'@phone',
      'salescar|1': ['宝马', '奥迪', '本田', '日立','特斯拉'],
      vincode:'@integer(311234,821234)',
      salesprice:'@float(0, 100, 2, 2)',
      paytype:'@integer(1,3)',
      fullpaystate:'@integer(0,1)',
      extraaddstate:'@integer(0,2)',
      insurancestate:'@integer(0,2)',
      agencystate:'@integer(0,2)',
      redemptioncert:'@integer(0,1)',
      salestate:'@integer(0,6)',
      createtime:'@datetime',
    }))
  
  }

const OperationList=[];
for(let i=0;i<7;i++){
    OperationList.push(Mock.mock({
      id: '@increment',
      operator:'@first',
      reason:'@phone',
      createtime:'@datetime',
    }))
  
  }

module.exports=[
    //salesliplist
    {
        url: '/api/sales/salesliplist',
        type: 'get',
        response: config => {
          const { importance, type, title, page = 1, limit = 20, sort } = config.query
    
          let mockList = SaleSlipList.filter(item => {
            if (importance && item.importance !== +importance) return false
            if (type && item.type !== type) return false
            if (title && item.title.indexOf(title) < 0) return false
            return true
          })
    
          if (sort === '-id') {
            mockList = mockList.reverse()
          }
    
          const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
    
          return {
            code: '10000',
            data: {
              total: mockList.length,
              items: pageList
            }
          }
        }
    },

    //operationlist
    {
        url: '/api/sales/operationlist',
        type: 'get',
        response: config => {
          let mockList = OperationList.filter(item => {
              return true;
          })
            return {
                code: '10000',
                data: {
                  total: mockList.length,
                  items: mockList
                }
              }
        }
    },

    //salesdetails
    {
        url: '/api/sales/salesdetails',
        type: 'get',
        response: config => {
            var rd=parseInt(Math.random()*count);
            var item= SaleSlipList[rd];
            return {
                code: '10000',
                data: item
              }
        }
    },
]